<?php
namespace app\mobile\controller;

use app\common\controller\Frontend;
use app\common\model\Category;
use app\common\model\App;
use think\Cache;




class Index extends Frontend
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = '';

    public function index()
    {

        $Category=new Category();
        $category=$Category->getCategoryArray();
        $this->assign('category',$category);


        $App=new App();
        $cate=$App->getCateNameList();
        $this->assign('cate',$cate);

        //获取首页所需数据
        $index_data=$this->get_index_data();
        $this->assign($index_data);


        return $this->fetch("index/index");
    }


    public function get_index_data(){
        $cache_name="mobile_index_data";
        //Cache::rm($cache_name);//////
        if(Cache::has($cache_name)){
            $index_data=Cache::get($cache_name);
        }else{

            //最新新闻
            $new_news_list=db("news")
                ->where(["status"=>1])
                ->field(["id","title","create_time"])
                ->order("id","desc")
                ->limit(0,40)
                ->select();

            $bt=db('app')->where('cate_name','BT')->field(['id','app_name','type_name','create_time','img'])->limit(0,40)->select();
            //单机
            $dj=db('app')->where('cate_name','单机')->field(['id','app_name','type_name','create_time','img'])->limit(0,40)->select();
            //应用
            $yy=db('app')->where('cate_name','应用')->field(['id','app_name','type_name','create_time','img'])->limit(0,40)->select();
            //网游
            $wy=db('app')->where('cate_name','网游')->field(['id','app_name','type_name','create_time','img'])->limit(0,40)->select();



            $index_data=[
                "dj"=>$dj,
                "wy"=>$wy,
                "bt"=>$bt,
                "yy"=>$yy,
                "new_news_list"=>$new_news_list
            ];
            Cache::set($cache_name,$index_data,86400);
        }

        return $index_data;

    }




}

